package edu.ccut.saturn.studio.logic.model.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnTransactionRollBackNode;

public class TransactionRollbackLoader extends NodeLoader {

	@Override
	public List<Shape> loadNodes(Element root) {
		
		NodeList transactionRollbackNodes = root.getElementsByTagName(SaturnTransactionRollBackNode.KEY_NODE_TRANSATIONTOLLBACK);
		
		List<Shape> shapes = new ArrayList<Shape>(transactionRollbackNodes.getLength());
		
		for (int i = 0; i < transactionRollbackNodes.getLength(); ++i) {
			SaturnTransactionRollBackNode transactionRollbackNode = new SaturnTransactionRollBackNode();
			Node transactionrollbackNode = transactionRollbackNodes.item(i);
			String shapeId = super.getNodeAttributeValue(transactionrollbackNode, Shape.KEY_ATTRIBUTE_SHAPE_ID);
			String nextId = super.getNodeAttributeValue(transactionrollbackNode, Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID);
			String name = super.getNodeElementValue(transactionrollbackNode, SaturnTransactionRollBackNode.SHOW_NODE_TRANSATIONROLLBACK_NAME);
			String description = super.getNodeElementValue(transactionrollbackNode, SaturnTransactionRollBackNode.SHOW_NODE_TRANSATIONROLLBACK_DESCRIPTION);
			
			Point location = super.getLocation(transactionrollbackNode);
			Dimension size = new Dimension(50, 70);
			
			transactionRollbackNode.setNode(transactionrollbackNode);
			transactionRollbackNode.setId(shapeId);
			transactionRollbackNode.setLocation(location);
			transactionRollbackNode.setName(name);
			transactionRollbackNode.setNextId(nextId);
			transactionRollbackNode.setDescription(description);
			transactionRollbackNode.setSize(size);
			
			shapes.add(transactionRollbackNode);
		}
		
		return shapes;
	}

}

